<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
    <input type="checkbox"/>测试数据 <br/>
</div>
<hr/>
<input type="button" value="全选" id="selectAll"/>
<input type="button" value="全不选" id="noSelect"/>
<input type="button" value="反选" id="select"/>
</body>
<script>
    function isArrayLike ( array ) {

        var length = array && array.length;

        return typeof length === 'number' && length >= 0;

    }

    function each ( array, callback ) {
        var i, k;
        if ( isArrayLike( array ) ) {
            // 使用 for 循环
            for ( i= 0; i < array.length; i++ ) {
                if( callback.call( array[ i ], i, array[ i ] ) === false ) break;
            }
        } else {
            // 使用 for-in 循环
            for ( k in array ) {
                if( callback.call( array[ i ], k , array[ k ] ) === false ) break;
            }
        }
        return array;
    }

    function itcast(selector){
        var list = document.querySelectorAll(selector);
        return{
            nodes:list,
            each:function(callback){
                each(this.nodes,callback)
            }

        }
    }

    //封装一个返回对象的函数
    function itcast(selector){
        var list=document.querySelectorAll(selector)
        return{
            nodes:this.list,
            each:function (callback){
                each(this.nodes,callback)
            }
        }
    }

    //封装维数组
    function itcast(selector){
        var arr = {length:0};
        var list=document.querySelectorAll(selector)
        [].push.apply(arr,list);
        arr.each=function(callback){
            each(arr,callback)
        };
        return arr;
    };
    itcast('#selectAll').nodes[0].onclick=function(){
        itcast('div>input').each(function(){
            this.checked=true;
        })
    }
</script>
</html>